package heima3_2.cn.osc.presenter.synthesize_particulars_presenter;

import android.content.Context;

import heima3_2.cn.osc.constant.Constants;
import heima3_2.cn.osc.model.bean.BlogBean;
import heima3_2.cn.osc.model.bean.GeneralBlogDetailBean;
import heima3_2.cn.osc.presenter.BasePresenter;
import heima3_2.cn.osc.ui.main_fragment.synthesize_particulars_fragment.RecommendParticularsFragment;
import heima3_2.cn.osc.utils.PreferencesUtils;
import retrofit2.Call;
import retrofit2.Response;

/**
 * Created by Administrator on 2017/1/17 0017.
 */

public class RecommendParticularsPresenter extends BasePresenter<GeneralBlogDetailBean> {
    private  RecommendParticularsFragment mRecommendParticularsFragment;
    private  Context mContext;

    public RecommendParticularsPresenter(Context context, RecommendParticularsFragment recommendParticularsFragment){
        this.mContext=context;
        this.mRecommendParticularsFragment=recommendParticularsFragment;
    }
    @Override
    protected void getFailureData(Throwable t) {

    }

    @Override
    protected void getSuccessData(Response<GeneralBlogDetailBean> response) {
        GeneralBlogDetailBean body = response.body();
        BlogBean blog = body.getBlog();
        mRecommendParticularsFragment.mWvParticulars.loadUrl(blog.url);
    }

    @Override
    public void getData(int page) {
        int newsID = PreferencesUtils.getInt(mContext, Constants.RECOMMEND_ID);
        System.out.println("newsID"+newsID);
        if(newsID!=0){
            Call<GeneralBlogDetailBean> info = mRetrofitInterface.getBlogger(newsID);
            info.enqueue(mCallback);

        }
    }
}
